package com.xinzhidi.web.netty.service;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinzhidi.common.constant.AgreementConstants;
import com.xinzhidi.common.core.domain.model.LoginUser;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.exception.ServiceException;
import com.xinzhidi.common.utils.DateUtils;
import com.xinzhidi.common.utils.SecurityUtils;
import com.xinzhidi.common.utils.StringUtils;
import com.xinzhidi.common.utils.bean.BeanUtils;
import com.xinzhidi.common.utils.file.FileTypeUtils;
import com.xinzhidi.web.bigscreen.domain.vo.EnergyDataListVo;
import com.xinzhidi.web.equipment.domain.vo.EquipmentInfoVo;
import com.xinzhidi.web.equipment.service.EquipmentService;
import com.xinzhidi.web.netty.entity.*;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatUpdDto;
import com.xinzhidi.web.netty.entity.householdHeat.ReadData;
import com.xinzhidi.web.netty.entity.po.AgreementCommandPo;
import com.xinzhidi.web.netty.entity.po.AgreementHeatAvgPo;
import com.xinzhidi.web.netty.entity.vo.AgreementHeatInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementHeatListVo;
import com.xinzhidi.web.netty.mapper.AgreementHeatMapper;
import com.xinzhidi.web.netty.utils.FormatData;
import com.xinzhidi.web.netty.utils.HexadecimalUtil;
import com.xinzhidi.web.netty.utils.NettyUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 户用、单元热量协议-（实时数据）Service业务层处理
 *
 * @author cx
 * @date 2023-06-17
 */
@Service
@RequiredArgsConstructor
public class AgreementHeatService extends ServiceImpl<AgreementHeatMapper, AgreementHeat> {

    private final AgreementHeatMapper agreementHeatMapper;

    private final AgreementCommandService commandService;

    private final AgreementCommandFieldService commandFieldService;

    private final AgreementHeatHistoryService agreementHeatHistoryService;

    private final DeviceInstructionService deviceInstructionService;

    private final AgreementHouseholdValveService agreementHouseholdValveService;

    @Autowired
    private EquipmentService equipmentService;

    /**
     * 查询户用、单元热量协议-（实时数据）
     *
     * @param id 户用、单元热量协议-（实时数据）主键
     * @return 户用、单元热量协议-（实时数据）
     */
    public AgreementHeatInfoVo selectAgreementHeatById(Long id) {
        AgreementHeat agreementHeat = agreementHeatMapper.selectById(id);
        AgreementHeatInfoVo infoVo = new AgreementHeatInfoVo();
        BeanUtils.copyProperties(agreementHeat, infoVo);
        return infoVo;
    }

    /**
     * 查询户用、单元热量协议-（实时数据）列表
     *
     * @param dto 查询户用、单元热量协议-（实时数据）dto
     * @return 户用、单元热量协议-（实时数据）
     */
    public TableDataInfo<AgreementHeatListVo> selectAgreementHeatList(AgreementHeatListDto dto) {
        LambdaQueryWrapper<AgreementHeat> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(AgreementHeat::getId);
        return TableDataInfo.getDataTable(agreementHeatMapper.selectList(wrapper), (domain -> {
            AgreementHeatListVo vo = new AgreementHeatListVo();
            BeanUtils.copyProperties(domain, vo);
            return vo;
        }));
    }

    /**
     * 新增户用、单元热量协议-（实时数据）
     *
     * @param dto 新增户用、单元热量协议-（实时数据）dto
     * @return 结果
     */
    public int insertAgreementHeat(AgreementHeatAddDto dto) {
        LoginUser loginUser = SecurityUtils.getLoginUser();

        AgreementHeat agreementHeat = new AgreementHeat();
        BeanUtils.copyProperties(dto, agreementHeat);
        agreementHeat.setCreateBy(loginUser.getUserId().toString());
        agreementHeat.setCreateTime(DateUtils.getNowDate());
        return agreementHeatMapper.insert(agreementHeat);
    }

    /**
     * 修改户用、单元热量协议-（实时数据）
     *
     * @param dto 修改户用、单元热量协议-（实时数据）dto
     * @return 结果
     */
    public int updateAgreementHeat(AgreementHeatUpdDto dto) {
        LoginUser loginUser = SecurityUtils.getLoginUser();

        AgreementHeat agreementHeat = new AgreementHeat();
        BeanUtils.copyProperties(dto, agreementHeat);
        agreementHeat.setUpdateBy(loginUser.getUserId().toString());
        agreementHeat.setUpdateTime(DateUtils.getNowDate());
        return agreementHeatMapper.updateById(agreementHeat);
    }

    /**
     * 批量删除户用、单元热量协议-（实时数据）
     *
     * @param ids 需要删除的户用、单元热量协议-（实时数据）主键
     * @return 结果
     */
    public int deleteAgreementHeatByIds(Long[] ids) {
        return agreementHeatMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除户用、单元热量协议-（实时数据）信息
     *
     * @param id 户用、单元热量协议-（实时数据）主键
     * @return 结果
     */
    public int deleteAgreementHeatById(Long id) {
        return agreementHeatMapper.deleteById(id);
    }

    /**
     * 接收热量数据
     *
     * @param deviceInstruction 下发指令
     * @param message           消息
     * @param protocolType      类型   4：户用热量协议  5：单元热量协议
     */
//    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> receiveHeat(String message, DeviceInstruction deviceInstruction, String protocolType) {
        //1：获取改回复指令的下发指令是哪条数据(户用、单元热量协议-历史数据表type为1的最后一条数据
        //2：获取协议指令表（agreement_command）、协议指令字段表（agreement_command_field）数据
        //3：解析数据，组装实体类
        //4:保存户用阀门协议-实时数据表（agreement_household_valve）、户用阀门协议-历史数据表（agreement_household_valve_history）
        //5：更新指令发送表（device_instruction）状态

//        LambdaQueryWrapper<AgreementHeatHistory> wrapper = new LambdaQueryWrapper<>();
//        wrapper.orderByDesc(AgreementHeatHistory::getCreateTime).last(" limit 1");

        LambdaQueryWrapper<AgreementCommand> commandWrapper = new LambdaQueryWrapper<>();
        commandWrapper.eq(AgreementCommand::getType, AgreementConstants.InstructionType.RECEIVE)
                .eq(AgreementCommand::getProtocolType, deviceInstruction.getProtocolType())
                .eq(AgreementCommand::getInstructType, deviceInstruction.getInstructType());
        AgreementCommand command = commandService.getOne(commandWrapper);

        LambdaQueryWrapper<AgreementCommandField> commandFieldLambdaQueryWrapper = new LambdaQueryWrapper<>();
        commandFieldLambdaQueryWrapper.eq(AgreementCommandField::getCommandId, command.getId())
                .orderByAsc(AgreementCommandField::getSort);
        List<AgreementCommandField> commandFieldList = commandFieldService.list(commandFieldLambdaQueryWrapper);
        Map<String, Object> map = new HashMap<>();
        for (AgreementCommandField commandField : commandFieldList) {
            Integer startNum = commandField.getStartNum();
            Integer endNum = commandField.getEndNum();
            String value = NettyUtils.getByteStr(startNum, endNum, message, commandField);
            FileTypeUtils.setValueByType(commandField.getFieldEnglish(), commandField.getFieldType(), map, value);
        }
        //保存户用阀门、单元热量、楼栋协议-实时数据表（agreement_heat）、户用阀门、单元人热量协议-历史数据表（agreement_heat_history）
        saveAgreementHeat(message, map, command, deviceInstruction, protocolType);
        return map;
    }

    /**
     * 保存户用阀门、单元人热量协议-实时数据表（agreement_heat）、户用阀门、单元热量协议-历史数据表（agreement_heat_history）
     */
//    @Transactional(rollbackFor = Exception.class)
    public void saveAgreementHeat(
            String message,
            Map<String, Object> map,
            AgreementCommand command,
            DeviceInstruction deviceInstruction,
            String protocolType) {
        AgreementHeat heat;
        //判断实时数据是否已存在，存在则更新，不存在则新增
        AgreementHeatListDto dto = new AgreementHeatListDto();
        dto.setDtuId(deviceInstruction.getDtuId());
        dto.setAddress(deviceInstruction.getAddress());
        dto.setInstructType(command.getInstructType());
        dto.setProtocolType(protocolType);
        heat = this.getAgreementHeat(dto);
        String dataFieldSerialNumber = this.getDataFieldSerialNumber(dto);
        if (heat != null) {
            heat.setInstructionSet(message);
            heat.setJsonData(JSON.toJSONString(map));
            heat.setUpdateTime(DateUtils.getNowDate());
        } else {
            heat = new AgreementHeat();
            heat.setDeviceInstructionId(deviceInstruction.getId());
            heat.setDtuId(deviceInstruction.getDtuId());
            heat.setProtocolName(command.getProtocolName());
            heat.setInstructType(command.getInstructType());
            heat.setInstructName(command.getInstructName());
            heat.setPlotId(deviceInstruction.getPlotId());
            heat.setBuildId(deviceInstruction.getBuildId());
            heat.setUnitId(deviceInstruction.getUnitId());
            heat.setHouseholdId(deviceInstruction.getHouseholdId());
            heat.setDeviceType(command.getDeviceType());
            heat.setAddress(deviceInstruction.getAddress());
            heat.setInstructionSet(message);
            heat.setJsonData(JSON.toJSONString(map));
        }
        heat.setProtocolType(protocolType);
        heat.setProtocolName(command.getProtocolName());
        heat.setDataFieldSerialNumber(dataFieldSerialNumber);
        if (this.saveOrUpdate(heat)) {
            LambdaQueryWrapper<AgreementCommand> commandWrapper = new LambdaQueryWrapper<>();
            commandWrapper.eq(AgreementCommand::getType, AgreementConstants.InstructionType.RECEIVE)
                    .eq(AgreementCommand::getProtocolType, deviceInstruction.getProtocolType())
                    .eq(AgreementCommand::getInstructType, deviceInstruction.getInstructType());
            command = commandService.getOne(commandWrapper);
            //保存户用阀门协议-历史数据表（agreement_household_valve_history）
            AgreementHeatHistory heatHistory = new AgreementHeatHistory();
            heatHistory.setDeviceInstructionId(deviceInstruction.getId());
            heatHistory.setDtuId(deviceInstruction.getDtuId());
            heatHistory.setProtocolName(command.getProtocolName());
            heatHistory.setInstructType(command.getInstructType());
            heatHistory.setInstructName(command.getInstructName());
            heatHistory.setPlotId(deviceInstruction.getPlotId());
            heatHistory.setBuildId(deviceInstruction.getBuildId());
            heatHistory.setUnitId(deviceInstruction.getUnitId());
            heatHistory.setHouseholdId(deviceInstruction.getHouseholdId());
            heatHistory.setDeviceType(command.getDeviceType());
            heatHistory.setAddress(deviceInstruction.getAddress());
            heatHistory.setInstructionSet(message);
            heatHistory.setPrefix(command.getPrefix());
            heatHistory.setDeviceType(command.getDeviceType());
            heatHistory.setControlCode(command.getControlCode());
            heatHistory.setLengthField(command.getLengthField());
            heatHistory.setStartChar(command.getStartChar());
            heatHistory.setJsonData(JSON.toJSONString(map));
            heatHistory.setDataFieldMark(command.getDataMark());
            heatHistory.setEndMark(command.getEndMark());
            heatHistory.setProtocolType(protocolType);
            heatHistory.setProtocolName(command.getProtocolName());
            heatHistory.setDataFieldSerialNumber(dataFieldSerialNumber);
            agreementHeatHistoryService.save(heatHistory);
        }
        deviceInstruction.setStatus(AgreementConstants.InstructSendingState.RETURN_TO_NORMAL);
        deviceInstructionService.updateById(deviceInstruction);
    }

    public AgreementHeat getAgreementHeat(AgreementHeatListDto dto) {
        AgreementHeat heat = agreementHeatMapper.selectOne(buildGenTableQueryWrapper(dto));
        return heat;
    }

    private LambdaQueryWrapper<AgreementHeat> buildGenTableQueryWrapper(AgreementHeatListDto dto) {
        LambdaQueryWrapper<AgreementHeat> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(StringUtils.isNotBlank(dto.getInstructType()), AgreementHeat::getInstructType, dto.getInstructType())
                .eq(StringUtils.isNotNull(dto.getDtuId()), AgreementHeat::getDtuId, dto.getDtuId())
                .eq(StringUtils.isNotBlank(dto.getAddress()), AgreementHeat::getAddress, dto.getAddress());
        return wrapper;
    }

    /**
     * 获取序列号---dataFieldSerialNumber
     */
    public String getDataFieldSerialNumber(AgreementHeatListDto dto) {
        Integer number = 0;
        AgreementHeat heat = this.getAgreementHeat(dto);
        if (heat == null) {
            return number.toString();
        }

        number = Integer.valueOf(heat.getDataFieldSerialNumber());
        if (number == 256) {
            number = 0;
        } else {
            number++;
        }

        return String.valueOf(number);
    }

    /**
     * 获取住户热量表实时数据（读热量表数据）
     */
    public ReadData getHouseholdHeatData(AgreementHeatListDto dto) {
//        HouseholdData unitData = baseMapper.getUnitData(dto.getHouseholdId());
        ReadData householdHeatData = baseMapper.getHouseholdHeatData(dto);
//        if (unitData != null && householdHeatData != null) {
//            householdHeatData.setHouseholdData(unitData);
//        }
        return householdHeatData;
    }

    /**
     * 获取住户热量表实时数据某个字段的平均值
     */
    public BigDecimal getAvgValue(AgreementHeatAvgPo po) {
        BigDecimal avgValue = this.baseMapper.getAvgValue(po);
        return avgValue;
    }

    /**
     * 获取供回水温度平均值
     */
    public BigDecimal getAverageAndReturnWaterValue(AgreementHeatAvgPo po) {
        BigDecimal avgValue = this.baseMapper.getAverageAndReturnWaterValue(po);
        return avgValue;
    }

    /**
     * 户用热量表-【热量表时间设置】指令下发
     */
    public boolean writeHouseholdTime(Long dtuId, String address, String time) {
        //获取序列号
        AgreementHeatListDto dto = new AgreementHeatListDto();
        dto.setProtocolType(AgreementConstants.AgreementType.HOUSEHOLD_HEAT_METER);
        dto.setDtuId(dtuId);
        dto.setAddress(address);
        dto.setInstructType("1");
        time = HexadecimalUtil.convertToHighLow(time , 1);
        //获取序列号
        String ser = FormatData.tenToHexadecimal(Integer.valueOf(this.getDataFieldSerialNumber(dto)), 1);
        time = ser + time;
        return this.saveDeviceInstruction("4", dtuId, address, "1", time);
    }

    /**
     * 组装指令表数据
     */
    public boolean saveDeviceInstruction(String protocolType, Long dtuId, String address, String instructType, String value) {

        //获取设备信息
        EquipmentInfoVo infoVo = equipmentService.getEquipmentInfoVo(dtuId, address);

        AgreementCommandPo agreementCommandPo = new AgreementCommandPo();
        agreementCommandPo.setProtocolType(protocolType);
        agreementCommandPo.setType(AgreementConstants.InstructionType.SEND);
        agreementCommandPo.setInstructType(instructType);
        AgreementCommand command = commandService.getProtocolInstruction(agreementCommandPo);
        if (command == null) {
            throw new ServiceException("指令不存在！");
        }
        String message = commandService.assemblyHouseholdValveInstruction(command, address, value);

        DeviceInstruction instruction = new DeviceInstruction();
        //组装DeviceInstruction数据
        instruction.setDtuId(dtuId);
        instruction.setBusinessType(AgreementConstants.InstructBusinessType.OTHER);
        instruction.setProtocolType(protocolType);
        if(protocolType.equals(AgreementConstants.AgreementType.HOUSEHOLD_HEAT_METER)){
            instruction.setProtocolName(AgreementConstants.AgreementTypeName.HOUSEHOLD_HEAT_METER);
        }
        else if(protocolType.equals(AgreementConstants.AgreementType.UNIT_HEAT_METER)){
            instruction.setProtocolName(AgreementConstants.AgreementTypeName.UNIT_HEAT_METER);
        }else if(protocolType.equals(AgreementConstants.AgreementType.SEAHORSE_VALVE_METER)){
            instruction.setProtocolName(AgreementConstants.AgreementTypeName.SEAHORSE_VALVE_METER);
        }

        instruction.setInstructType(command.getInstructType());
        instruction.setInstructName(command.getInstructName());
        instruction.setPlotId(infoVo.getLotId());
        instruction.setBuildId(infoVo.getBuildId());
        instruction.setUnitId(infoVo.getUnitId());
        instruction.setHouseholdId(infoVo.getHouseholdId());
        instruction.setAddress(infoVo.getAddress());
        instruction.setInstructionSet(message);
        boolean flag = deviceInstructionService.save(instruction);
        return flag;
    }

    /**
     * 组装指令表数据
     */
    public DeviceInstruction getDeviceInstruction(String protocolType, Long dtuId, String address, String instructType, String value) {

        //获取设备信息
        EquipmentInfoVo infoVo = equipmentService.getEquipmentInfoVo(dtuId, address);

        AgreementCommandPo agreementCommandPo = new AgreementCommandPo();
        agreementCommandPo.setProtocolType(protocolType);
        agreementCommandPo.setType(AgreementConstants.InstructionType.SEND);
        agreementCommandPo.setInstructType(instructType);
        AgreementCommand command = commandService.getProtocolInstruction(agreementCommandPo);

        if (command == null) {
            throw new ServiceException("指令不存在！");
        }
        String message = commandService.assemblyHouseholdValveInstruction(command, address, value);

        DeviceInstruction instruction = new DeviceInstruction();
        //组装DeviceInstruction数据
        instruction.setDtuId(dtuId);
        instruction.setBusinessType(AgreementConstants.InstructBusinessType.OTHER);
        instruction.setProtocolType(protocolType);
        if(protocolType.equals(AgreementConstants.AgreementType.HOUSEHOLD_HEAT_METER)){
            instruction.setProtocolName(AgreementConstants.AgreementTypeName.HOUSEHOLD_HEAT_METER);
        }
        else if(protocolType.equals(AgreementConstants.AgreementType.UNIT_HEAT_METER)){
            instruction.setProtocolName(AgreementConstants.AgreementTypeName.UNIT_HEAT_METER);
        }else if(protocolType.equals(AgreementConstants.AgreementType.SEAHORSE_VALVE_METER)){
            instruction.setProtocolName(AgreementConstants.AgreementTypeName.SEAHORSE_VALVE_METER);
        }

        instruction.setInstructType(command.getInstructType());
        instruction.setInstructName(command.getInstructName());
        instruction.setPlotId(infoVo.getLotId());
        instruction.setBuildId(infoVo.getBuildId());
        instruction.setUnitId(infoVo.getUnitId());
        instruction.setHouseholdId(infoVo.getHouseholdId());
        instruction.setAddress(infoVo.getAddress());
        instruction.setInstructionSet(message);
        return instruction;
    }


    /**
     * 户用热量表-【读地址】指令下发
     */
    public boolean readHouseholdHeatAddress(Long dtuId) {
        return agreementHouseholdValveService.readAddress(AgreementConstants.AgreementType.HOUSEHOLD_HEAT_METER, "3", dtuId);
    }

    /**
     * 户用热量表-【设置地址】指令下发
     */
    public boolean writeHouseholdHeatAddress(Long dtuId, String oldAddress, String newAddress) {
        return agreementHouseholdValveService.saveAddressDeviceInstruction(AgreementConstants.AgreementType.HOUSEHOLD_HEAT_METER, "4", dtuId, oldAddress, newAddress);
    }

    /**
     * 户用热量表-【阀门强开】指令下发
     */
    public boolean openValve(Long dtuId, String address, String value) {
        value = FormatData.tenToHexadecimal(Integer.valueOf(value), 1);
        return this.saveDeviceInstruction("4", dtuId, address, "5", value);
    }

    /**
     * 户用热量表-【阀门强关】指令下发
     */
    public boolean closeValve(Long dtuId, String address, String value) {
        value = FormatData.tenToHexadecimal(Integer.valueOf(value), 1);
        return this.saveDeviceInstruction("4", dtuId, address, "6", value);
    }


    /**
     * 单元热量表-【读地址】指令下发
     */
    public boolean readUnitHeatAddress(Long dtuId) {
        return agreementHouseholdValveService.readAddress(AgreementConstants.AgreementType.UNIT_HEAT_METER, "2", dtuId);
    }

    /**
     * 单元热量表-【设置地址】指令下发
     */
    public boolean writeUnitHeatAddress(Long dtuId, String oldAddress, String newAddress) {
        return agreementHouseholdValveService.saveAddressDeviceInstruction(AgreementConstants.AgreementType.UNIT_HEAT_METER,"3", dtuId, oldAddress, newAddress);
    }

    /**
     * 单元热量表-【热量表时间设置】指令下发
     */
    public boolean writeUnitTime(Long dtuId, String address, String time) {
        //获取序列号
        AgreementHeatListDto dto = new AgreementHeatListDto();
        dto.setProtocolType(AgreementConstants.AgreementType.UNIT_HEAT_METER);
        dto.setDtuId(dtuId);
        dto.setAddress(address);
        dto.setInstructType("4");

        time = HexadecimalUtil.convertToHighLow(time , 1);
        //获取序列号
        String ser = FormatData.tenToHexadecimal(Integer.valueOf(this.getDataFieldSerialNumber(dto)), 1);
        time = ser + time;
        return this.saveDeviceInstruction("5", dtuId, address, "4", time);
    }

    /**
     * 单元热量表-【阀门强开】指令下发
     */
    public boolean unitOpenValve(Long dtuId, String address, String value) {
        value = FormatData.tenToHexadecimal(Integer.valueOf(value), 1);
        return this.saveDeviceInstruction("5", dtuId, address, "5", value);
    }

    /**
     * 单元热量表-【阀门强关】指令下发
     */
    public boolean UnitCloseValve(Long dtuId, String address, String value) {
        value = FormatData.tenToHexadecimal(Integer.valueOf(value), 1);
        return this.saveDeviceInstruction("5", dtuId, address, "6", value);
    }

    /**
     * 通过单元id获取他下面住户的热量指标平均值
     * @author cx
     * @date 2023/10/21 10:50
     * @param buildUnitId 单元id
     * @return java.util.Map<java.lang.String,java.lang.String>
     **/
    public Map<String , String> getAvgByBuildUnitId(Long buildUnitId){
        return this.baseMapper.getAvgByBuildUnitId(buildUnitId);
    }

    /**
     * 通过单元id获取他下面住户的总热量和总流量
     * @author cx
     * @date 2023/10/21 10:50
     * @param buildUnitId 单元id
     * @return java.util.Map<java.lang.String,java.lang.String>
     **/
    public Map<String , String> getTotalHeatByBuildUnitId(Long buildUnitId){
        return this.baseMapper.getTotalHeatByBuildUnitId(buildUnitId);
    }

    /**
     * 通过楼栋id获取他下面单元的总热量和总流量
     * @author cx
     * @date 2023/10/21 10:50
     * @param buildId 楼栋id
     * @return java.util.Map<java.lang.String,java.lang.String>
     **/
    public Map<String , String> getTotalHeatByBuildId(Long buildId){
        return this.baseMapper.getTotalHeatByBuildId(buildId);
    }

    /**
     * 通过单元id获取他下面住户的阀门开度指标平均值
     * @author cx
     * @date 2023/10/21 10:50
     * @param buildUnitId 单元id
     * @return java.util.Map<java.lang.String,java.lang.String>
     **/
    public EnergyDataListVo getAvgValveByBuildUnitId(Long buildUnitId){
        return this.baseMapper.getAvgValveByBuildUnitId(buildUnitId);
    }

    /**
     * 通过楼栋id获取他下面单元的阀门开度指标平均值
     * @author cx
     * @date 2023/10/21 10:50
     * @param buildId 楼栋id
     * @return java.util.Map<java.lang.String,java.lang.String>
     **/
    public EnergyDataListVo getAvgValveByBuildId(Long buildId){
        return this.baseMapper.getAvgValveByBuildId(buildId);
    }

    /**
     * 通过楼栋id获取他下面单元的热量指标平均值
     * @author cx
     * @date 2023/10/21 10:50
     * @param buildId 楼栋id
     * @return java.util.Map<java.lang.String,java.lang.String>
     **/
    public Map<String , String> getAvgByBuildId(Long buildId){
        return this.baseMapper.getAvgByBuildId(buildId);
    }


}
